package com.xiao.dynamic_rule.engine;

import com.xiao.dynamic_rule.functions.DeviceKeySelector;
import com.xiao.dynamic_rule.functions.Json2BeanMapFunction;
import com.xiao.dynamic_rule.functions.RuleProcessFunctionV3;
import com.xiao.dynamic_rule.utils.KafkaUtils;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

/**
 * @description:
 * @author: 啸
 * @date: 2022/9/2 14:35
 */
public class RuleEngineV3 {
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        FlinkKafkaConsumer<String> kafkaCounsumer = KafkaUtils.getFlinkKafkaCounsumer("hadoop101:9092,hadoop102:9092,hadoop103:9092",
                "latest",
                "applog");
        DataStreamSource<String> sourceDS = env.addSource(kafkaCounsumer);

        sourceDS
                .map(new Json2BeanMapFunction())
                .keyBy(new DeviceKeySelector())
                .process(new RuleProcessFunctionV3())
                .print();

        try {
            env.execute();
        } catch (Exception e){
            e.printStackTrace();
        }

    }
}
